<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <script type="module">
        import Stack from './Stack.js'
        
        function decimalToBinary(decNumber){
            // 存储余数的栈
            const remStack = new Stack();
            // 十进制数
            let number = decNumber;
            // 余数
            let rem;
            // 二进制字符串
            let binaryString = '';
            
            while (number > 0) {
                // 对二取余，向下取整
                rem = Math.floor( number % 2 );
                // 余数推入栈
                remStack.push(rem);
                // 十进制数除以二
                number = Math.floor( number / 2 );
            }
            
            while(!remStack.isEmpty()) {
                // 拼接字符串  按顺序移除栈内元素（与推进相反） 
                binaryString += remStack.pop().toString();
            }
            
            return binaryString;
        }

        console.log(decimalToBinary(233));
        console.log(decimalToBinary(10));
        console.log(decimalToBinary(1000));
    </script>
</body>
</html>